package com.project.weimi.adapter;

import java.util.List;

import com.project.weimi.R;
import com.project.weimi.activity.ExchangeDetailActivity;
import com.project.weimi.entity.response.IntegralExchangeEntity;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class IntegralExchangeAdapter extends BaseAdapter{

	private Context context;
	private List<IntegralExchangeEntity> list;
	
	public IntegralExchangeAdapter(Context context, List<IntegralExchangeEntity> list) {
		super();
		this.context = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if(convertView == null){
			vh = new ViewHolder();
			// 解析布局文件
			convertView = LayoutInflater.from(context).inflate(R.layout.integral_exchange_listview_item, null);
			// 获得控件对象
			vh.img = (ImageView)convertView.findViewById(R.id.img);
			vh.tv_content = (TextView)convertView.findViewById(R.id.tv_content);
			vh.tv_integral = (TextView)convertView.findViewById(R.id.tv_integral);
			vh.tv_exchange = (TextView)convertView.findViewById(R.id.tv_exchange);
			convertView.setTag(vh);
		}else{
			vh = (ViewHolder) convertView.getTag();
		}
		
		vh.tv_exchange.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// 跳转到兑换详情页面
				Intent intent = new Intent(context,ExchangeDetailActivity.class);
				context.startActivity(intent);
			}
		});
		
		
		vh.img.setImageResource(list.get(position).getImgs());
		vh.tv_content.setText(list.get(position).getContent());
		vh.tv_integral.setText(list.get(position).getIntegral());

		
		return convertView;
	}

	
	class ViewHolder{
		ImageView img;
		TextView tv_content;
		TextView tv_integral;
		TextView tv_exchange;
	}
	
	
}
